<%-- 
    Document   : service
    Created on : Jun 18, 2013, 7:01:45 PM
    Author     : Anna SAELEE
--%>

<%@page import="java.util.Date"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link type="text/css" rel="stylesheet" href="style.css"/>
        <title>Demander des services</title>
    </head>
    <%  Connection conn;
        Statement stmt;
        ResultSet rs;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/dormitorymanagement", "root", "root");
            stmt = conn.createStatement();%>
    <body>
        <div class="wrapper">
            <div class="header"></div>
            <div class="navigator"> <a href="#">MENU</a> > <a href="#">SUBMENU</a> 30*1000 </div>
            <div class="workspace">
                <%@include file="connect.jsp" %>
                <div class="workspace2">
                    <h3>Demander des services</h3>
                    <%String sql = "SELECT r_number FROM account WHERE username='" + session.getAttribute("username") + "'";
                        String room = "";
                        rs = stmt.executeQuery(sql);
                        if (rs.next()) {
                            room = rs.getString("r_number");
                        }
                        if (session.getAttribute("username") == null || session.getAttribute("username").equals("admin")) {%>
                    Vous n'avez pas de droit pour cette page!
                    <% } else if (room == null) {%>
                    Vous n'avez pas encore vous inscrit dans la chambre donc vous ne pouvez pas de droit à utiliser cette fonction!
                    <% } else {%>
                    <form method="post" action="Enregistrer" name="orderService">
                        <input type="hidden" name="typeMss" value="orderService"/>
                        <% String username = (String) session.getAttribute("username");
                            SimpleDateFormat SimpleDate = new SimpleDateFormat("yyyy-MM-dd");
                            Date now = new Date();
                            String date = SimpleDate.format(now);%>
                        <input type="hidden" name="username" value="<%=username%>"/>
                        <input type="hidden" name="room" value="<%=room%>"/>
                        <table border="0" align="center">
                            <tr>
                                <th>Date: </th>
                                <td><input type="hidden" name="date" value="<%= date%>"/><%= date%></td>
                            </tr>
                            <tr>
                                <th>Catégorie: </th>
                                <td>
                                    <% sql = "SELECT cid, cname FROM category WHERE type='service' ORDER BY cid";
                                        rs = stmt.executeQuery(sql);%>
                                    <select name="category">
                                        <option value="0">Choisir un ...</option>
                                        <% while (rs.next()) {%>
                                        <option value="<%= rs.getString("cid")%>"><%= rs.getString("cname")%></option>
                                        <% }%>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <th>Message: </th>
                                <td><textarea name="message" rows="20" cols="50">
                                        <% String message = (String) session.getAttribute("message");
                                            if (message == null) {
                                                message = "";
                                            }
                                            out.println(message);%>
                                    </textarea></td>
                            </tr>
                            <tr>
                                <td colspan="2" style="text-align: center">
                                    <input type="submit" name="sendOrder" value="Envoyer la demande"/>
                                </td>
                            </tr>
                        </table>
                    </form>
                    <% }%>
                </div>
                <%@include file="sidespace.jsp" %>
            </div>
            <div class="footer"> FOOTER 80*1000 </div>
        </div>
    </body>
    <% } finally {
            out.close();
        }
    %>
</html>